package com.bee.study.serice;

import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.Set;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2019-8-9
 */
@Service
public class ScheduledTest {

    @Resource
    private Jedis jedis;

//    @Scheduled(fixedDelay = 1000)
    public String testPop() {
        System.out.println("*******************定时任务开始!*******************");
//        Set<Tuple> result = jedis.zrangeWithScores("aa", 0, -1);
        Set<Tuple> result = jedis.zrevrangeWithScores("aa", 0, -1);
        Iterator<Tuple> iterator = result.iterator();
        while (iterator.hasNext()){
            Tuple s = iterator.next();
            double score = s.getScore();
//            if (score < new Date().getTime()) {
                System.out.println("获取的数据core：" + s.getScore());
                System.out.println("获取的数据value：" + s.getElement());
                if (s.getElement() != null) {
                    Long userNo = jedis.zrem("aa", s.getElement());
                    System.out.println("删除参数：" + s.getElement());
                }
//            }
        }
        Long userNo = jedis.zrem("aa", "jj");
        System.out.println("测试没有值的:" + userNo);
        return result.toString();
    }
}
